package sui.plugins
{
    import sui.Settings;
    import sui.core.Component;
    import sui.core.sui_internal;
    import sui.reflect.Type;

    public class PluginManager
    {
        private static var _instance:PluginManager;

        public static function getInstance():PluginManager
        {
            if (_instance == null)
            {
                _instance = new PluginManager;
                Settings.init();
            }
            return _instance;
        }

        public static function add(plugin:IPlugin):void
        {
            getInstance().add(plugin);
        }

        /*
         *
         */
        private var plugins:Vector.<IPlugin>;

        public function PluginManager()
        {
            plugins = new Vector.<IPlugin>;
        }

        /**
         *
         * @param component
         *
         */
        sui_internal function onConstruct(component:Component):void
        {
            var description:Type = Type.get(component);
            for each (var plugin:IPlugin in plugins)
            {
                plugin.onConstruct(component, description);
            }
        }

        /**
         *
         * @param component
         *
         */
        sui_internal function onRender(component:Component):void
        {
        }

        private function add(plugin:IPlugin):void
        {
            plugins.push(plugin);
        }
    }
}
